<?php
declare (strict_types = 1);

namespace app\listener;

class SwWsMessage
{
    /**
     * xiaoxi
     *
     * @return mixed
     */
    public function handle($event, \think\swoole\websocket $ws)
    {
         $fd = $ws->getSender();
         $data = json_encode($event);
         echo "receive from {$fd}:{$data}\n";
         $ws->emit("this is server", $fd);
        //$ws = app('think\swoole\Websocket');
		//获取当前发送消息客户端的 fd
        //var_dump($ws->getSender());
        //发送给指定 fd 的客户端，包括发送者自己
        //$ws->to(intval($event['to']))->emit('test',$event['message']);
    }
}